/*
 * @lc app=leetcode.cn id=690 lang=javascript
 *
 * [690] 员工的重要性
 */

// @lc code=start
/**
 * Definition for Employee.
 * function Employee(id, importance, subordinates) {
 *     this.id = id;
 *     this.importance = importance;
 *     this.subordinates = subordinates;
 * }
 */

/**
 * @param {Employee[]} employees
 * @param {number} id
 * @return {number}
 */
var GetImportance = function(employees, id) {
   let findPerson=function(employees,id){
       return employees.find((item)=>item.id==id)
   }
   let queue=[findPerson(employees,id)]
   let imp=0
   while(queue.length){
    let person=queue.shift()
    imp+=person.importance
    if(person.subordinates.length!==0){
        for(let i=0;i<person.subordinates.length;i++){
            queue.push(findPerson(employees,person.subordinates[i]))
        }
    }
   }
   return imp
};
// @lc code=end
console.log(GetImportance([[1,2,[2]], [2,3,[]]],2))
var GetImportance = function(employees, id) {
    let find=function(employees,id){
    let per=[]
    for(let i=0;i<employees.length;i++){
        if(employees[i][0]===id){
            per=employees[i];
            break;
        }
    }
    return per}
    let imp=0
    let dfs=function(person){
        imp+=person[1]
        if(person[2].length==0)return
        for(let i of person[2]){
            let temp=find(employees,i)
            dfs(temp)
        }
    }
    dfs(find(employees,id))
    return imp
};//dfs